package com.bitnpulse.dev2.jjh.engstudybook_free.view.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bitnpulse.dev2.jjh.engstudybook_free.R;
import com.bitnpulse.dev2.jjh.engstudybook_free.beans.ContentsArrayBean;
import com.bitnpulse.dev2.jjh.engstudybook_free.view.holder.Holder;

public class CustomAdapter extends BaseAdapter{
	
	private Context _mContext;
	private ArrayList<ContentsArrayBean> _mContentsArray;
	
	public CustomAdapter(Context context, ArrayList<ContentsArrayBean> contentsArray) {
		this._mContext = context;
		this._mContentsArray = contentsArray;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return _mContentsArray.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return _mContentsArray.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if( null == convertView ){
			convertView = View.inflate(_mContext, R.layout.listview_holder, null);
			TextView txtTitle = (TextView)convertView.findViewById(R.id.txt_title);
			
			Holder holder = new Holder();
			holder.txtTitle = txtTitle;
			convertView.setTag(holder);
		}
		
		String title = _mContentsArray.get(position).title;
		
		Holder holder = (Holder)convertView.getTag();
		holder.txtTitle.setText(title);
		
		return convertView;
	}
	
}